<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/18 0018
 * Time: 15:59
 */

namespace Admin\Controller;



use Admin\Model\GoodsModel;

class ArticleController extends CommonController
{
    public function index(){
        $data = M('article_list  a ')
            ->field('a.*,b.column_name,c.name')
            ->join('left join agency_article_column   b on a.column_id = b.column_id ')
            ->join('left join agency_user_admin   c on a.admin_id = c.admin_id ')
            ->select();

        foreach($data as $key=>$v){
            $cc=$v['article_text'];
            $text=str_replace(array("\r\n", "\r", "\n"," "),'',strip_tags($cc));
            $data[$key]['article_text']=mb_substr($text,0,50,'utf-8').(mb_strlen($text,'UTF8')>50?"......":"");
        }
//        $text = str_replace(array("\r\n", "\r", "\n"," "), '', strip_tags($article_column[$k]['list'][$kk]['article_text']));
//        $article_column[$k]['list'][$kk]['article_text'] = mb_substr($text,0,50,'utf-8').(mb_strlen($text,'UTF8')>50?"......":"");

        $this->assign('list',$data);
        $this->display();
    }

    public function add(){


        if(IS_POST){
            $data = $_POST;
            //$data['admin_id']=$_SESSION['userid'];

            $rel = M('article_list')->add($data);
            if($rel){
                die(json_encode(array('state'=>200,'rel'=>'成功！')));
            }

        }

        $db = M('article_column');
        $cate = $this->getCateTree($db,$id=0,$pid='parent_column_id',$zid='column_id');
        $this->assign('cate',$cate);
        $this->display();
    }
}